package com.neuedu.common.file.domain.model;

import com.neuedu.common.file.domain.model.enums.FileTypeEnum;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import cn.hutool.core.util.StrUtil;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FileRequest {

    private FileTypeEnum type;

    /**
     * 路径"/"为间隔
     */
    private String filePath;

    private String fileName;

    private String rawFilePath;

    private String rawFileName;

    public String getRawFilePath() {
        return parseFilePath(rawFilePath);
    }

    public String getFilePath() {
        return parseFilePath(filePath);
    }

    public FileRequest(String filePath, String fileName) {
        this.filePath = filePath;
        this.fileName = fileName;
    }

    private String parseFilePath(String filePath) {
        if (StrUtil.isBlank(filePath)) {
            return null;
        }
        if (!filePath.endsWith("/")) {
            filePath += "/";
        }

        return filePath;
    }

}
